package com.top.mall.main.order.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.lemlin.image.loadCenterImage
import com.top.mall.R
import com.top.mall.entity.OrderGood
import com.top.mall.entity.OrderList

class OrderGroupAdapter : BaseQuickAdapter<OrderList, BaseViewHolder>(R.layout.item_order_group),
    LoadMoreModule {

    init {
        addChildClickViewIds(
            R.id.rvOrderGroupQrCode,
            R.id.rvOrderGroupReturn,
            R.id.rvOrderGroupDelete,
            R.id.rvOrderGroupCancel,
            R.id.rvOrderGroupRevoke,
            R.id.rvOrderGroupUpdate,
            R.id.rvOrderGroupAgain,
            R.id.rvOrderGroupPayment
        )
    }

    override fun convert(holder: BaseViewHolder, item: OrderList) {
        holder.setText(R.id.rvOrderGroupCount, "共${item.order_goods.size}件，实付")
            .setText(R.id.rvOrderGroupPrice, "￥${item.order_amount}")
            .setText(R.id.tvOrderGroupStatus, if (item.pay_status == "0") "待支付" else "待发货")
            .setGone(R.id.rvOrderGroupPayment, item.pay_status == "1")
            .setText(R.id.tvOrderGroupTime, item.order_sn)
        holder.getView<RecyclerView>(R.id.rvOrderGroupGoods).adapter =
            OrderGoodsAdapter().apply {
                setNewInstance(item.order_goods)
                setFooterView(createFooterView())
            }
    }

    private fun createFooterView(): View = TextView(context).apply {
        text = "..."
        textSize = 16f
        setTextColor(context.resources.getColor(R.color.FF_333333))
        setPadding(ConvertUtils.dp2px(63f), 0, 0, 0)
    }
}

class OrderGoodsAdapter :
    BaseQuickAdapter<OrderGood, BaseViewHolder>(R.layout.item_goods_order_list) {
    override fun convert(holder: BaseViewHolder, item: OrderGood) {
        holder.setText(R.id.textView58, item.goods_name)
            .setText(R.id.textView64, "x${item.goods_num}")
            .getView<ImageView>(R.id.imageView19).loadCenterImage(item.image)
    }

}